package com.job.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.job.common.ResponseResult;
import com.job.common.enums.ResultCodeEnum;
import com.job.common.exception.AddCorporationException;
import com.job.common.exception.ParameterIsNullException;
import com.job.controller.req.CorporationInfoVO;
import com.job.controller.req.CorporationSearchVO;
import com.job.controller.req.HrCorporationVo;
import com.job.controller.req.PageVo;
import com.job.controller.resp.CorporationInfoRespVO;
import com.job.pojo.vo.CorporationVO;
import com.job.service.CorporationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Api("公司管理")
@RequestMapping("/corporation")
public class CorporationController {

    @Resource
    private CorporationService corporationService;

    @ApiOperation("公司搜索")
    @GetMapping("/search")
    public ResponseResult<Page<CorporationVO>> corporationSearch(@Valid CorporationSearchVO corporationSearchVO)
            throws ParameterIsNullException {
        return corporationService.corporationSearch(corporationSearchVO);
    }

    @ApiOperation("公司列表")
    @GetMapping("/corporationList")
    public ResponseResult<Page<CorporationVO>> corporationList(@Valid PageVo pageVo) throws ParameterIsNullException {
        CorporationSearchVO corporationSearchVO = new CorporationSearchVO(pageVo.getCurrent(), pageVo.getSize());
        return corporationService.corporationSearch(corporationSearchVO);
    }

    @ApiOperation("公司详情")
    @GetMapping("/context")
    public ResponseResult<CorporationInfoRespVO> corporationInfoContext(@Valid CorporationInfoVO corporationInfoVO)
            throws ParameterIsNullException {
        return corporationService.corporationInfoContext(corporationInfoVO);
    }

    @ApiOperation("添加公司信息")
    @PostMapping("/addCorporation")
    public ResponseResult<ResultCodeEnum> corporationInfoContext(@Valid @RequestBody HrCorporationVo hrCorporationVo)
            throws AddCorporationException {
       return corporationService.corporationAdd(hrCorporationVo);
    }
}
